/* OpenProcessing Tweak of *@*http://www.openprocessing.org/sketch/72079*@* */
/* !do not delete the line above, required for linking your tweak if you upload again */
//slider
class ColorPicker{
  boolean open=false;
Slider S1 ;
PVector posS1 ;
PVector sizeS1 ;
float valueS1 ;
//palette
Palette P1 ;
PVector posP1, sizeP1 ;
//setup color
color rouge, orange, blanc, noir ;
color picked=-1;

//setup slider
int thicknessSlider ;
int followS1 ; 
color colorSlider, colorBorderSlider ; 
int posX,posY;

ColorPicker(int posX,int posY) 
{
  //size(275,400-128); 
  //colorMode (HSB, 255 ) ; 
  //smooth() ;;
  this.posX=posX;
   this.posY=posY;
  rouge = color(0,200,200) ; orange = color (40,250,250) ; blanc = color(0,0,255) ; noir = color (0,0,0) ;
  //Setup slider
  followS1 = 10 ;
  //setup color and draw slider
  colorSlider = blanc ;  colorBorderSlider = noir ;
  thicknessSlider = 1 ;

  //slider activation
  posS1 = new PVector  (posX+10, posY+15, 0 ) ;
  sizeS1 = new PVector (128, 10, 0 ) ;
  S1 = new Slider(posS1, sizeS1, followS1, colorSlider,  colorBorderSlider, thicknessSlider);
  
  //palette activation
  posP1 = new PVector ( posX+10, posY+30, 0 ) ;
  sizeP1 = new PVector (128, 128, 0 ) ;
  P1 = new Palette(posP1, sizeP1);
  open=true;
}
/////////////////////////////
void Draw() 
{  
  
  if(!open)
  {
      
      return ;
  }
  if(!P1.open)
  {
    open=false;
    picked=P1.currentColor;
    println(picked);
    P1.closePalette();
    S1.closeSlider();
  }
  

  //background( 0 );
  ///////////////////////////SLIDER///////////////
  //return of the value from slider
  fill(255);
  rect(posX,posY,145,250);
  valueS1 = S1.getPos() ;
  /////////////update slider
  S1.update();
  
  ////////////display slider
  //S1.slider(); // classic
  S1.sliderColor(); // special
  
  ////////////////display molette
  PVector ratio = new PVector (0.5, 2.0 ) ; // give the size of the molette ratio X different of "zero", ratio "y" must be bigger than "one"
  // color of molette for the rollover
  color moletteIN = blanc ; 
  color moletteOUT = noir ;
  color moletteBorderIN = blanc ; 
  color moletteBorderOUT = noir ;
  int moletteThickness = 1 ;
  int typeOfMolette = 2 ; // 1 = rect ; 2 = ellipse ; you can create others shapes if you want in the class Slider.
  
  S1.molette(ratio, moletteIN, moletteOUT, moletteBorderIN, moletteBorderOUT, moletteThickness, typeOfMolette) ;
  
  /////////////////////////////PALETTE//////////////////
  float valueSlider = valueS1 ; // this float give the value from the slider or other parameter, value between 0 to 255
  P1.display( valueSlider ) ; 
  
  // color witness
  //new color
  PVector posNC = new PVector  ( posX+10.0 , posY+300-128.0 ) ;
  PVector sizeNC = new PVector ( sizeP1.x , 20.0 ) ;
  P1.newColor(posNC, sizeNC) ;
  //currentColor
  PVector posCC = new PVector  ( posX+10.0 , posY+320.0-128.0 ) ;
  PVector sizeCC = new PVector ( sizeP1.x , 20.0 ) ;
  P1.currentColor(posCC, sizeCC) ;
  
  //buton
  PVector posB = new PVector ( posX+10.0,posY+ 350.0-128.0 ) ;
  PVector sizeB = new PVector ( 75.0 , 20.0 ) ;
  color buttonIN = blanc ; 
  color buttonOUT = noir ;
  color buttonBorderIN = blanc ; 
  color buttonBorderOUT = noir ;
  color colorTitle = rouge ;
  int   buttonThickness = 1 ;
  int   typeOfButton = 1 ; // 1 = rect ; 2 = ellipse ; you can create others shapes if you want in the class Slider.
  String title = "Pick" ;
  P1.buttonValidate (posB, sizeB, buttonIN, buttonOUT, buttonBorderIN, buttonBorderOUT, buttonThickness, typeOfButton, title, colorTitle ) ;
  //if(!P1.open)
  //  open=false;

}

void Move(int posX,int posY) 
{
    this.posX=posX;
   this.posY=posY;
}
color getColor()
{ color(RGB,255); 
  
  return picked;
}
void openColorPicker()
{
  open=true;
  P1.openPalette();
  S1.openSlider();
}
void closeColorPicker()
{
  open=false;
  P1.closePalette();
  S1.closeSlider();
}
}
